package h0919;
/**
  * @description 装最多水的容器
  * @author 不知名帅哥
  * @date 2024/9/19 18:32
  * @version 1.0
*/
public class FillWaterContainer {

    public static int trap(int[] height) {
        if (height==null||height.length==0){
            return 0;
        }
        int left=0;
        int right=height.length-1;
        int area=0;
        //TODO 跟接雨水不同的是，这个类似于连通器
        while (left<right){
            if(height[left]<height[right]){
                int h=height[left];
                area=Math.max(area,h*(right-left));
                left++;
            }else {
                int h=height[right];
                area=Math.max(area,h*(right-left));
                right--;
            }
        }
        return area;
    }

    public static void main(String[] args) {
        int[] heights={1,8,6,2,5,4,8,3,7};
        System.out.println(trap(heights));
    }
}
